//
//  JXHomeVC.swift
//  WBTest
//
//  Created by Fantasy on 2016/12/8.
//  Copyright © 2016年 Fantasy. All rights reserved.
//

import UIKit

// 定义全局常量
private let cellId = "cellId"

// 方法
class JXHomeVC: JXBaseViewController {
    
    // 懒加载微博模型数组
    lazy var statusList = [String]()
    
    override func loadData() {
        
        for i in 0..<15 {
            if self.isPullup {
                // 将数据追加到底部
                self.statusList.append("上拉 \(i)")
            } else {
                self.statusList.insert(i.description, at: 0)
            }
        }
        print("刷新结束")
        
        self.refreshControl?.endRefreshing()
        self.isPullup = false
        self.tableView?.reloadData()
    }
    
    @objc func leftItemClick() {
        let vc = JXTestViewController()
        navigationController?.pushViewController(vc, animated: true)
    }
}


// MARK: - 表格数据源方法
extension JXHomeVC {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count;
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        
        // 设置cell
        cell.textLabel?.text = statusList[indexPath.row]
        
        return cell
    }
}


// MARK: - UI布局
extension JXHomeVC {
    override func setupUI() {
        super.setupUI()
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(leftItemClick))
    
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
    }
}
